package ah.cgen;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;


import freemarker.template.TemplateException;

public class GenTest {
	private Gen gen;
	
	@BeforeClass
    public static void enter() {
        System.out.println("进来了！");
    }
	
	@Before
	public void init() throws IOException {
		gen = new Gen();
	}
	
	/**
	 * 单个类
	 */
	@Test
	public void oneClass() {
		
		String beanName = "KhhShortUrl";
		
		try {
			gen.genJava(beanName);
			
			List<String> beanNames = new ArrayList<String>();
			beanNames.add(beanName);
			//gen.genSpringXml(beanNames);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 类目录
	 * @throws IOException
	 * @throws TemplateException
	 */
//	@Test
	public void classDir() throws IOException, TemplateException{
		File dir = new File("/home/ddh/workspace/MPBao/src/com/wos/mpbao/database/domain");
		File[] files = dir.listFiles(new FileFilter() {
			
			public boolean accept(File pathname) {
				if (pathname.getName().endsWith(".java")) {
					return true;
				}
				return false;
			}
		});
		List<String> beanNames = new ArrayList<String>();
		
		for (File file : files) {
			String fileName = file.getName();
			fileName = fileName.replace(".java", "");
			try {
				gen.genJava(fileName);
				beanNames.add(fileName);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		
	}
	
	/**
	 * 类数组
	 * @throws IOException
	 * @throws TemplateException
	 */
//	@Test
	public void classArr() throws IOException, TemplateException{
		String[] fileNames = {"JhglQjndjhBzzb", "JhglQjndjhXxyh", "JhglQjndjhZxgc"};
		
		List<String> beanNames = new ArrayList<String>();
		
		for (String fileName : fileNames) {
			try {
				gen.genJava(fileName);
				beanNames.add(fileName);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
